home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / uwserver.zip / uwserver.tar / h / uw_opt.h < prev    next >
C/C++ Source or Header  |  1991-01-25  |  6KB  |  162 lines

  1. /*
  2.  *    uw window options
  3.  *
  4.  * Copyright 1986 by John D. Bruner.  All rights reserved.  Permission to
  5.  * copy this program is given provided that the copy is not sold and that
  6.  * this copyright notice is included.
  7.  *
  8.  * Some protocols support the transmission of window options.  A window
  9.  * option is a parameter (or collection of related parameters) which
  10.  * describes the layout, appearance, or other characteristic of a
  11.  * window.  Some options are common to all window types, while others
  12.  * are window emulation-specific.
  13.  *
  14.  * Window options may be "set" by one side on its own initiative or in
  15.  * response to an "inquiry" from the other side.  In addition, one side
  16.  * may request that the other side "report" changes in options.
  17.  *
  18.  * Options are passed as part of a "new window" command or as part of
  19.  * an "option" command (as defined by the protocol, above).  The option
  20.  * format has been chosen to minimize the need for protocol encoding
  21.  * of special or meta characters.
  22.  */
  23.  
  24. #ifndef    UW_OPT
  25. #define    UW_OPT
  26.  
  27. typedef unsigned int woptcmd_t;        /* window option command: */
  28. #define    WOC_SET        0        /*    request current option value */
  29. #define    WOC_INQUIRE    2        /*    report current option value */
  30. #define    WOC_DO        4        /*    do report changes to option */
  31. #define    WOC_DONT    5        /*    don't report changes */
  32. #define    WOC_WILL    6        /*    will report changes */
  33. #define    WOC_WONT    7        /*    won't report changes */
  34. #define    WOC_MASK    7        /*    mask */
  35. #define    WOC_BADCMD(n)    ((n)==1 || (n)==3)
  36.  
  37. /*
  38.  * Option commands include an option number specifier.  If the option
  39.  * number is in the range 1-14 a short-form specifier can be used;
  40.  * otherwise, a long-form specifier must be used.  Option (sub)command
  41.  * bytes consist of 7 bits of data.  The lower order 3 bits specify the
  42.  * option command.  The next higher 4 bits specify the option number.
  43.  * The value zero is reserved (as described below).  If the option
  44.  * number is greater than 14, these four bits specify 017 (15) and the
  45.  * option number is specified in a second byte.  The value is encoded
  46.  * by adding ' ' to the option number.  Multiple options may be specified
  47.  * in one command -- the last option is followed by a reference to
  48.  * "option" 0 (as an endmarker).
  49.  */
  50.  
  51. typedef unsigned int woption_t;        /* window option number: */
  52. #define    WONUM_MIN    1        /*    minimum option number */
  53. #define    WONUM_GENERIC    7        /*    maximum generic option number */
  54. #define    WONUM_SHORT    14        /*    maximum short option number */
  55. #define    WONUM_MAX    31        /*    maximum option number */
  56. #define    WONUM_MASK    (017<<3)    /*    mask for extraction */
  57. #define    WONUM_USELONG(n) ((unsigned)(n) > WONUM_SHORT)
  58. #define    WONUM_SENCODE(n) (((n)&017)<<3)    /*     short encoding function */
  59. #define    WONUM_SDECODE(b) (((b)>>3)&017)    /*     short decoding function */
  60. #define    WONUM_LPREFIX    (017<<3)    /*    long encoding prefix */
  61. #define    WONUM_LENCODE(n) ((n)+' ')    /*     long encoding function */
  62. #define    WONUM_LDECODE(c) (((c)&0177)-' ') /*     long decoding function */
  63.  
  64.  
  65. /*
  66.  * The following option numbers are generic (recognized for all window
  67.  * types):
  68.  */
  69. #define    WOG_END        0        /* [endmarker] */
  70. #define    WOG_VIS        1        /* 0=invisible, 1=visible */
  71. #define    WOG_TYPE    2        /* window emulation type (see below) */
  72. #define    WOG_POS        3        /* window position on screen */
  73. #define    WOG_TITLE    4        /* window title */
  74. #define    WOG_SIZE    5        /* window size (in bits) */
  75. #define    WOG_6        6        /* unassigned, reserved */
  76. #define    WOG_7        7        /* unassigned, reserved */
  77.  
  78. /*
  79.  * Option arguments immediately follow option (sub)command bytes.  They are
  80.  * encoded to prevent interference with flow-control and IAC recognition.
  81.  * Three types of options are recognized: non-graphic character strings of
  82.  * fixed length, general character strings of variable length, and binary
  83.  * numbers of fixed width.
  84.  *
  85.  * Non-graphic character strings are transmitted directly.  They CANNOT
  86.  * include IAC, XON, or XOFF and should not include "meta" characters.
  87.  *
  88.  * General character strings are encoded in the UW protocol fashion: "meta"
  89.  * characters and special characters are escaped.  The string is terminated
  90.  * with a null byte.  The string may not exceed some predetermined maximum
  91.  * number of characters (which may be less than or equal to 256, including
  92.  * the terminating null byte).
  93.  *
  94.  * Binary numbers are transmitted in 6-bit chunks, least-significant bits
  95.  * first.  The number of 6-bit chunks required depends upon the width of
  96.  * the number.  The 0100 bit in each byte is always set to prevent
  97.  * collisions with special characters (such as flow control and IAC).
  98.  */
  99.  
  100. /*
  101.  * Implementation:
  102.  *
  103.  * Arrays of type "woptarg_t" are used to describe the arguments associated
  104.  * with each option.  (Note that arguments are associated only with
  105.  * the "set" option subcommand.)
  106.  */
  107.  
  108. typedef unsigned woptarg_t;        /* option argument type: */
  109. #define    WOA_END        0        /*    endmarker */
  110. #define    WOA_CHARS(n)    ((1<<8)|(n))    /*    "n" untranslated characters */
  111. #define    WOA_STRING(m)    ((2<<8)|(m))    /*    string of max length "m" */
  112. #define    WOA_UDATA(b)    ((3<<8)|(b))    /*    binary number "b" bits wide */
  113. #define    WOA_CMDMASK    0177400        /* command mask */
  114.  
  115. typedef long woptbmask_t;        /* option bitmask (>= 32 bits wide) */
  116. #define    WOPT_SET(mask,bit)    ((mask) |= (1<<(bit)))
  117. #define    WOPT_CLR(mask,bit)    ((mask) &= ~(1<<(bit)))
  118. #define    WOPT_ISSET(mask,bit)    ((mask) & (1<<(bit)))
  119.  
  120. struct woptdefn {
  121.     woptbmask_t    wod_pending;    /* pending notifications to Mac */
  122.     woptbmask_t    wod_inquire;    /* pending inquiries from Mac */
  123.     woptbmask_t    wod_do;        /* pending DO commands to Mac */
  124.     woptbmask_t    wod_dont;    /* pending DONT commands to Mac */
  125.     woptbmask_t    wod_askrpt;    /* reports (of changes) we ask for */
  126.     struct woptlst {
  127.         woptarg_t    *wol_argdefn;    /* option argument definition */
  128.         char        *(*wol_get)();    /* called to get option value */
  129.         void        (*wol_set)();    /* called to set option value */
  130.         void        (*wol_ext)();    /* called for external window */
  131.     }        wod_optlst[WONUM_MAX+1];
  132. };
  133.  
  134. /*
  135.  * The following structure is used by routines that fetch and set option
  136.  * values.
  137.  */
  138. union optvalue {
  139.     unsigned char    ov_udata1;
  140.     unsigned char    ov_udata2;
  141.     unsigned char    ov_udata6;
  142.     unsigned short    ov_udata12;
  143.     struct {
  144.         unsigned short    v,h;
  145.     }        ov_point;
  146.     char        ov_string[256];
  147. };
  148.  
  149. /*
  150.  * When it is necessary to convert between host byte order and network
  151.  * byte order, opt_netadj() is called.  A pointer to the following
  152.  * structure is passed.
  153.  */
  154. struct netadj {
  155.     short        (*na_short)();
  156.     long        (*na_long)();
  157.     unsigned short    (*na_ushort)();
  158.     unsigned long    (*na_ulong)();
  159. };
  160.  
  161. #endif
  162.